<template>
  <div class="app-container">
    <el-table
      stripe
      border
      height="450"
      :data="tableData"
      style="width: 100%"
      :header-cell-style="{'text-align': 'center'}"
    >
      <el-table-column
        prop="maintenanceTurbine"
        label="维修机组编号"
        align="center"
      />
      <el-table-column
        prop="maintenanceMan"
        label="维修人员工号"
        align="center"
      />
      <el-table-column
        prop="maintenanceType"
        label="维修类型"
        align="center"
      />
      <el-table-column
        prop="maintenanceTime"
        label="维修时间"
        align="center"
      />
      <el-table-column
        prop="maintenanceAction"
        label="维修动作"
        align="center"
      />
      <el-table-column
        prop="maintenanceLevel"
        label="维修等级"
        align="center"
      />
      <el-table-column
        prop="addr"
        label="操作"
        align="center"
        width="150"
      >
        <template v-slot="scope">
          <el-button type="danger" size="mini" @click="handleDelete(scope.row)">已完成</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        :current-page.sync="currentPage"
        :page-size="pageSize"
        layout="total, prev, pager, next, jumper"
        :total="total"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { delMaintain, getAllIngFaultInfo, updateOkFaultManange, updateDevice } from '@/api/de_repair'
import { editMaintainer } from '@/api/maintainer'

export default {
  name: 'PreTable',
  data() {
    return {
      total: 1,
      pageSize: 1,
      currentPage: 1,
      tableData: [],
      maintainers: {
        jobNumber: '',
        maintenanceContents: '',
        startProcessTime: '',
        endProcessTime: ''
      },
      Faultmanange: {
        faultTurbine: ''
      },
      Device: {
        turbineId: '',
        turbineStatus: ''
      }
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      getAllIngFaultInfo().then(({ data }) => {
        this.total = data.page.total
        this.pageSize = data.page.pageSize
        this.tableData = data.page.records
        this.isShow1 = false
      })
    },
    handleCurrentChange(pageNum) {
      getAllIngFaultInfo(pageNum).then(({ data }) => {
        this.tableData = data.page.records
      })
    },
    handleDelete(row) {
      this.Faultmanange.faultTurbine = row.maintenanceTurbine
      this.maintainers.jobNumber = row.maintenanceMan
      this.Device.turbineId = row.maintenanceTurbine
      this.Device.turbineStatus = '正常运转'
      this.$confirm('请确定此机组维修已完成', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delMaintain(row.maintenanceTurbine).then(() => {
          updateOkFaultManange(this.Faultmanange).then(() => {
            editMaintainer(this.maintainers).then(() => {
              updateDevice(this.Device).then(() => {
                this.$message({
                  type: 'success',
                  message: '维修任务完成成功!'
                })
                // 重新获取列表的接口
                this.handleCurrentChange(this.currentPage)
              })
            })
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消完成'
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
